﻿using B.S.Data.MES.API.Applications.AccountApplication.Command;
using B.S.Domain.Accounts;
using B.S.Infratrctrue;
using B.S.Requst;
using MediatR;
using Microsoft.EntityFrameworkCore;

namespace B.S.Data.MES.API.Applications.AccountApplication.CommandHandler
{
    public class FactorySelectCommandHandler : IRequestHandler<FactorySelectCommand, APIRequst<List<FactoryClass>>>
    {
        public FactorySelectCommandHandler(IBaseRepository<FactoryClass> factoryrepository)
        {
            Factoryrepository = factoryrepository;
        }

        public IBaseRepository<FactoryClass> Factoryrepository { get; }

        public async Task<APIRequst<List<FactoryClass>>> Handle(FactorySelectCommand request, CancellationToken cancellationToken)
        {
            return new APIRequst<List<FactoryClass>>
            {
                Code = RequstCode.成功,
                Msg = "工厂信息获取成功",
                Data = await Factoryrepository.GetAll().ToListAsync()
            };
        }
    }
}
